﻿package bonus {
	
	import field.Ball;
	import field.Element;
	import flash.display.MovieClip;
	import field.GamePanel;
	
	
	public class Rainbow extends Bonus {
		
		
		public function Rainbow() {
			// constructor code
		}
		
		public override function apply(): void {
			main.panel.disappearBallsUnderCursor();
			
			super.apply();
		}
		
		public override function select(tileX: Number, tileY: Number): void {
			var currentColor: Number = 0;
			var currentBall: Ball = null;
			
			if ( ! (main.panel.elements[tileY][tileX] is Ball))
				return;
			currentColor = Ball(main.panel.elements[tileY][tileX]).color;
			
			for (var i: Number = 0; i < GamePanel.DIMENSION_HEIGHT; i++) {
				for (var j: Number = 0; j < GamePanel.DIMENSION_WIDTH; j++) {
					
					if ( main.panel.elements[i][j] is Ball)
						currentBall = main.panel.elements[i][j];
					else continue;
					
					if (currentBall == null)
						continue;
					if (currentBall.color == currentColor) {
						main.panel.elementsUnderCursor [currentBall] = currentBall;
					}
				}
			}
			
			main.panel.blinkElementsUnderCursor();
		}
		
	}
	
}
